package elektra.plugin.environment;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;


public class AspectLogger implements MethodInterceptor {

	@Inject
	private IPluginContext context;
	public Object invoke(MethodInvocation invoke) throws Throwable {
		 context.getLogger().info(invoke.getThis().getClass().getSimpleName()+" : "+invoke.getMethod().getName()+"- TRY START");
		 long start=  System.currentTimeMillis();
		 Object result =  invoke.proceed();	     
		 long stop=  System.currentTimeMillis();
		 context.getLogger().info(invoke.getThis().getClass().getSimpleName()
				 +" : "+invoke.getMethod().getName()+"- EXECUTED:"+(stop-start)+"ms");
		 return result;
	}

}
